package com.ctwom.algorithm.questions.Csort;

/**
 * 冒泡排序O(N^2)
 * 思路：双层循环，外层确定遍历次数，内层找出两两比较最大值并放到数组最后面
 */
public class MaopaoSort {
    public static void main(String[] args) {
        int[] arr = {3,4,2,6,9,1,0,5};
        maopaoSort(arr);
        for (int i:arr){
            System.out.println(i);
        }
    }
    public static int[] maopaoSort(int[] arr){
        int length = arr.length;
        int i=0;
        while(i<length){
            int j = i;
            while(j<length-1){
                if(arr[j]>arr[j+1]){
                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
                j++;
            }
            length--;
        }
        return arr;
    }
}
